<template>
  <el-config-provider :locale="zhCn">
    <router-view />
  </el-config-provider>
</template>

<script setup lang="ts">
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// 导入水印 工具类
import watermark from '@/utils/watermark'
import { useGlobalStore } from './store/modules/global'
import dayjs from 'dayjs'
const globalStore = useGlobalStore()

// # 添加水印执行方法
const handleWaterMask = ({ name, userName }: { name: string; userName: string }) => {
  watermark.mark({
    watermark_txt: userName + '  ' + name + '  ' + dayjs().format('YYYY-MM-D HH:mm:ss'),
    watermark_alpha: 0.08 // 水印透明度
  })
}

watch(
  () => globalStore.userInfo,
  (currentUser) => {
    let name = currentUser?.name
    let userName = currentUser?.userName
    handleWaterMask({ name, userName })
  },
  {
    immediate: true,
    deep: true
  }
)

window.addEventListener('resize', () => {
  let name = globalStore.userInfo?.name
  let userName = globalStore.userInfo?.userName
  handleWaterMask({ name, userName })
})
</script>
